package com.xwqiang.service.impl;

import com.xwqiang.mapper.SysUserMapper;
import com.xwqiang.pojo.model.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Collections;


/**
 * 改造前
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        //通过查询库将SysUser 封装成 AuthorSysUser
        SysUser sysUser = sysUserMapper.selectByUsername(username);

        if (sysUser == null) {
            return null;
        }
        AuthorSysUser authorSysUser = new AuthorSysUser(sysUser, Collections.emptyList());
        return authorSysUser;
    }
}
